<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class ReplyController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $data = $request->except('_token');
        // dd($data);
        $a_time = $data['a_time'];
        $a_content = $data['a_content'];
        $uid = session('login');
        if($uid==null)
        {
            return back()->with('error','添加失败');
        }
        // dd($uid);
        $qid = $data['qid'];
        $pid = $data['a_id'];
        $path='0'.','.$pid;
        
        $res=DB::table('zy_answer')->insertGetId([
                    'uid'=>$uid,
                    'a_content'=>$a_content,
                    'a_time'=>$a_time,
                    'qid'=>$qid,
                    'pid'=>$pid,
                    'path'=>$path,
                    'a_status'=>'0'
            ]);

        if($res){
            return redirect('/home/answer/'.$qid);
        }else{
            return back();
        }

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
